<html>
<head> 

<title>ANGEL - RISCV JS ISA Simulator</title>

<link rel="stylesheet" href="lib/shepherd-0.4.2/shepherd-theme-arrows.css" />
<script src="lib/shepherd-0.4.2/shepherd.min.js"></script>
<link rel="stylesheet" href="lib/odometer/odometer-theme-default.css" />
<script src="lib/odometer/odometer.min.js"></script>

<script src="lib/screenfull/screenfull.js"></script>


<!-- load angel interface components -->
<script src="devices/character.js"></script>
<script src="utils.js"></script>

<!-- bootstrap -->
<link href="style/css/bootstrap.min.css" rel="stylesheet">
<link href="style/css/bootstrap-responsive.min.css" rel="stylesheet">
<link href="style/css/bootstrap-switch.css" rel="stylesheet">
<link href="style/css/jasny-bootstrap.min.css" rel="stylesheet">

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<script src="style/jquery/jquery.min.js"></script>
<script src="style/js/bootstrap.min.js"></script>

<style type="text/css">
    body { 
        padding-top: 20px;
        padding-bottom: 40px;
    }

    .container-narrow {
        margin: 0 auto;
        max-width: 960px;
    }

    .consBoxNoGlow:focus {
        outline: none;
        border: none;
    }

    .tooltip-inner {
        max-width: 500px;
    }
</style>

<!-- angel functions -->
<script>
function runWorker() {
    myWorker = new Worker("webworker.js");
    myWorker.onmessage = function(oEvent) {
        if (oEvent.data.type == "t") {
            // handle term event
            write_to_term(oEvent.data.d);
        } else if (oEvent.data.type == "p") {
            // handle prog bar event
            document.getElementById("bar").style.width = (oEvent.data.d*100).toString() + "%";
        } else if (oEvent.data.type == "tr") {
            // handle terminal read
            alert("READ HAPPENED");
        } else if (oEvent.data.type == "m") {
            // update MIPS counter
            document.getElementById('kernelDown').innerHTML = "Millions of Instructions Per Second";
            $("#kernelDown").hide();
            $("#progbar").hide();
            $('#mipsLabel').show();
            $("#mipsCount").show();
            document.getElementById("mipsCount").innerHTML = oEvent.data.d;
        }
    };
}
</script>
</head>

<body>

<div class="container">
    <div class="masthead" align="center">
        <h3><a href="#" id="ANGELtitle" data-toggle="tooltip" data-placement="bottom" title="ANGEL is Naturally Good at Executing Linux">ANGEL</a> - Browser-based RISC-V ISA simulator</h3>
    </div>

    <div class="row-fluid marketing">
        <div class="span12">

            <div class="tabbable">
                <ul class="nav nav-tabs">
                    <li class="active"><a href="#tab1" data-toggle="tab">Terminal</a></li>
                    <li><a href="#tab2" data-toggle="tab">Advanced Controls</a></li>
                </ul>
                <div class="tab-content">
                    <div class="tab-pane active" id="tab1"> 
                        <div id="buttonbox" class="span12" style="height: 50px;"><div class="span4">
                                <a id="bootButton" class="btn btn-medium btn-success" onclick="runWorker(); $('#consoleBox').focus();">Boot Linux</a> <input type="checkbox" label="Fullscreen Terminal" id="fullscreenOnRun"> Fullscreen Terminal   </div>


                            <div class="span3" id="kernelDown" align="right">Kernel download progress: </div>
                            <div id="progbar" class="progress progress-success span5" >
                                <div id="bar" class="bar" style="width: 0%;"></div>
                            </div>
                            <div class="span7" id="mipsLabel" align="right" style="vertical-align: middle; display:none; font-size: 20px;"> Millions of Instructions Per Second</div>
                            <div id="mipsCount" class="odometer span1" style="display:none; font-size: 30px;">0</div>

                        <br><br>
                    </div>
                    <br>
            <div id="consoleBox" tabindex="1" class="consBoxNoGlow" style="padding:5px; height:700px; background-color:black; overflow: auto; color:white; font-size:110%; font-family: Monaco, Consolas, Lucida Console, monospace;">

            <div id="console"></div>

            </div>
                    </div>

                    <div class="tab-pane" id="tab2">

                        <div class="span5">
                        <div><h4>Command Line Arguments:</h4> <input type="text" style="height: 32px; width:100%;" id="cmdargs" /> </div>

<div id="debugbuttons" style="position:relative;">
    <div style="float: left; width:40%; left: 0;">
        <h4><a href="#" data-toggle="tooltip" data-container="body" data-placement="bottom" title="Special tools for monitoring program execution.">Debug Mode</a>:</h4> 
    </div>
    <div id="debugtoggle" class="make-switch" data-on-label="ON" data-off-label="OFF" style="height: 30px; width: 30%; float:right; right: 0;">
        <input type="checkbox" id="debugcheckbox" checked="checked" />
    </div>
</div>
<br><br>
<div id="updatebuttons" style="position:relative;">
    <div style="float: left; width:60%; left: 0;">
        <h4><a href="#" data-toggle="tooltip" data-container="body" data-placement="bottom" title="Toggle updating register info. Off for increased clock freq.">Update Regboxes</a>:</h4> 
    </div>
    <div id="updatetoggle" class="make-switch" data-on-label="ON" data-off-label="OFF" style="height: 30px; width: 30%; float:right; right: 0;">
        <input type="checkbox" id="regtablecheckbox" <!--checked="checked"--> />
    </div>
</div>


<br><br>
<div id="debugbox" style="position:relative; width: 100%;">
<div>
<h5>Execution controls: </h5><a class="btn btn-medium btn-primary"  data-toggle="tooltip" data-container="body" data-placement="bottom" title="Execute next instruction."   onclick="#">></a>

<a class="btn btn-medium btn-primary"  data-toggle="tooltip" data-container="body" data-placement="bottom" title="Execute to completion." onclick="" >>></a>

<a class="btn btn-medium btn-primary"  data-toggle="tooltip" data-container="body" data-placement="bottom" title="After pausing, step through execution one instruction at a time with &gt; or resume execution with &gt;&gt; " onclick="pauseExec = true;" >Pause Execution</a>

</div>

                        <div><h5><a data-toggle="tooltip" data-container="body" data-placement="bottom" title="Enter space separated list of 0x-prefixed (hex) PC values to use as breakpoints. CPU will halt before the instruction at the specified address is executed. Breakpoints must be entered before elf file is loaded above.">Breakpoints</a>:</h5> <input type="text" style="height: 32px; width:100%;" id="breakpoints" /> </div>


<div style="font-family: Monaco, Consolas, Lucida Console, monospace;">
                        <table id="debugprops" class="table table-striped table-hover table-condensed table-bordered">
                            <tr>
                                <td>Debug Stats</td>
                                <td>Value</td>
                            </tr>
                            <tr>
                                <td>Execution not started</td>
                                <td></td>
                            </tr>

                        </table>
</div>

<div style="font-family: Monaco, Consolas, Lucida Console, monospace;">
                        <table id="elfprops" class="table table-striped table-hover table-condensed table-bordered">
                            <tr>
                                <td>ELF Property</td>
                                <td>Value</td>
                            </tr>
                            <tr>
                                <td>No ELF selected</td>
                                <td></td>
                            </tr>
                        </table>
</div>

                        <div id="testrestext">Test Result (for RV64 tests): </div>
                        <div id="testresult">ELF not loaded</div>

</div>

                    </div>
                    <div class="span7"> 
            <div id="regBoxWrapper">
                <div id="regLabel"><h5>Register Values</h5></div> 
                <div id="regLabelAlt"><h5>Register Values - Updating is OFF<h5></div>

            <div style="font-family: Monaco, Consolas, Lucida Console, monospace;">
            <table id="regtable" class="table table-striped table-hover table-condensed table-bordered">
                <tr>
                    <td>Register</td>
                    <td>Value (Hex)</td>
                    <td>Value (Unsigned Dec.)</td>
                </tr>
                <tr>
                    <td>x0 (zero)</td>
                    <td></td>
                    <td></td>
                </tr>
                <tr>
                    <td>x1 (ra)</td>
                    <td></td>
                    <td></td>
                </tr>
                <tr>
                    <td>x2 (s0)</td>
                    <td></td>
                    <td></td>
                </tr>
                <tr>
                    <td>x3 (s1)</td>
                    <td></td>
                    <td></td>
                </tr>
                <tr>
                    <td>x4 (s2)</td>
                    <td></td>
                    <td></td>
                </tr>
                <tr>
                    <td>x5 (s3)</td>
                    <td></td>
                    <td></td>
                </tr>
                <tr>
                    <td>x6 (s4)</td>
                    <td></td>
                    <td></td>
                </tr>
                <tr>
                    <td>x7 (s5)</td>
                    <td></td>
                    <td></td>
                </tr>
                <tr>
                    <td>x8 (s6)</td>
                    <td></td>
                    <td></td>
                </tr>
                <tr>
                    <td>x9 (s7)</td>
                    <td></td>
                    <td></td>
                </tr>
                <tr>
                    <td>x10 (s8)</td>
                    <td></td>
                    <td></td>
                </tr>
                <tr>
                    <td>x11 (s9)</td>
                    <td></td>
                    <td></td>
                </tr>
                <tr>
                    <td>x12 (sA)</td>
                    <td></td>
                    <td></td>
                </tr>
                <tr>
                    <td>x13 (sB)</td>
                    <td></td>
                    <td></td>
                </tr>
                <tr>
                    <td>x14 (sp)</td>
                    <td></td>
                    <td></td>
                </tr>
                <tr>
                    <td>x15 (tp)</td>
                    <td></td>
                    <td></td>
                </tr>
                <tr>
                    <td>x16 (v0)</td>
                    <td></td>
                    <td></td>
                </tr>
                <tr>
                    <td>x17 (v1)</td>
                    <td></td>
                    <td></td>
                </tr>
                <tr>
                    <td>x18 (a0)</td>
                    <td></td>
                    <td></td>
                </tr>
                <tr>
                    <td>x19 (a1)</td>
                    <td></td>
                    <td></td>
                </tr>
                <tr>
                    <td>x20 (a2)</td>
                    <td></td>
                    <td></td>
                </tr>
                <tr>
                    <td>x21 (a3)</td>
                    <td></td>
                    <td></td>
                </tr>
                <tr>
                    <td>x22 (a4)</td>
                    <td></td>
                    <td></td>
                </tr>
                <tr>
                    <td>x23 (a5)</td>
                    <td></td>
                    <td></td>
                </tr>
                <tr>
                    <td>x24 (a6)</td>
                    <td></td>
                    <td></td>
                </tr>
                <tr>
                    <td>x25 (a7)</td>
                    <td></td>
                    <td></td>
                </tr>
                <tr>
                    <td>x26 (t0)</td>
                    <td></td>
                    <td></td>
                </tr>
                <tr>
                    <td>x27 (t1)</td>
                    <td></td>
                    <td></td>
                </tr>
                <tr>
                    <td>x28 (t2)</td>
                    <td></td>
                    <td></td>
                </tr>
                <tr>
                    <td>x29 (t3)</td>
                    <td></td>
                    <td></td>
                </tr>
                <tr>
                    <td>x30 (t4)</td>
                    <td></td>
                    <td></td>
                </tr>
                <tr>
                    <td>x31 (gp)</td>
                    <td></td>
                    <td></td>
                </tr>
            </table>
        </div>
                        <div>

                </div>
            </div>
            </div>

        </div>

        </div>
    </div>

    <br><br>
    <div class="footer" style="text-align: center;">
        Based on <a href="http://riscv.org">The RISC-V Instruction Set Manual</a> <br>
        Source on <a href="https://github.com/ucb-bar/riscv-angel">Github</a> | Built by <a href="http://sagark.org">sagark</a> | <a href="LICENSE" id="lic" data-toggle="tooltip" data-placement="top" title="
Copyright (c) 2013-2014, The Regents of the University of California (Regents).
All Rights Reserved. 
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright
   notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
   notice, this list of conditions and the following disclaimer in the
   documentation and/or other materials provided with the distribution.
3. Neither the name of the Regents nor the
   names of its contributors may be used to endorse or promote products
   derived from this software without specific prior written permission.

IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING
OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF REGENTS HAS
BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE SOFTWARE AND ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED
HEREUNDER IS PROVIDED &quot;AS IS&quot;. REGENTS HAS NO OBLIGATION TO PROVIDE
MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
            ">License</a>
    </div>

</div>
</body>

<!-- misc end-of-page scripts -->
<script>

    init_term();

    // enable bootstrap tooltips
    $('a').tooltip();

    $('#debugtoggle').change(function() {
        $('#debugbox').toggle();
    });

    $('#regLabel').toggle();

    $('#updatetoggle').change(function() {
        $('#regLabel').toggle();
        $('#regLabelAlt').toggle();
    });

    flashConsoleCursor(); // start flashing console

    insertsSinceEnter = 0;
    $("#consoleBox").bind('keypress', function(event) {
        if (event.keyCode == 13) {
            //user hit enter
            forceConsoleDivDown();
            myWorker.postMessage({"type": "r"});
        } else if (event.keyCode == 32) {
            //user hit space
            myWorker.postMessage({"type": "u", "inp": String.fromCharCode(event.keyCode)});
        } else {
            myWorker.postMessage({"type": "u", "inp": String.fromCharCode(event.keyCode)});
        }
        //console.log(event.keyCode);
        event.preventDefault();
    });

// special backspace handling
$(document).unbind('keydown').bind('keydown', function (event) {
    var doPrevent = false;
    if (event.keyCode === 8) {
        var d = event.srcElement || event.target;
        if ((d.tagName.toUpperCase() === 'INPUT' && (d.type.toUpperCase() === 'TEXT' || d.type.toUpperCase() === 'PASSWORD' || d.type.toUpperCase() === 'FILE')) 
             || d.tagName.toUpperCase() === 'TEXTAREA') {
            doPrevent = d.readOnly || d.disabled;
        }
        else {
            doPrevent = true;
        }
    }

    if (doPrevent) {
        event.preventDefault();
myWorker.postMessage({"type": "u", "inp": String.fromCharCode(event.keyCode)});
    }
});

$(function() {
   $('#consoleBox').focus();
});


    var elem = document.getElementById('consoleBox');
    document.getElementById('bootButton').addEventListener('click', function () {
    if (screenfull.enabled && document.getElementById('fullscreenOnRun').checked) {
        screenfull.request(elem);
    }
});


</script>
<!-- set up shepherd helper for the user-->
<script src="ui/shepherdconfig.js"></script>

</html>
